import { Component } from 'react';
import { Card, Row, Col, Icon, Modal, Button, message } from 'antd';

import CompanysInfo from './companysInfo'
import CorporateInfo from './corporateInfo'
import Authentication from './authentication'
import AdministratorInfo from './administratorInfo'

import AuditResults from './auditResults'
import PropTypes from 'prop-types';
import { getDate, formatDate } from '@/utils/date';

const headStyle = {
  backgroundColor: '#FAFAFA',
  padding: '0 10px',
};
const changedImg = {
  border: '1px solid red',
};

class CompanyInformation extends Component {
  static propTypes = {
    information: PropTypes.object.isRequired,
    reviewResult: PropTypes.object.isRequired,
    userInformation:PropTypes.object,
  };

  state = {
    tableKey: Date.now(),
  };

  render() {
    const {
      history:history,
      information,
      reviewResult,
      dispatch,
      companyChangeLog,
      userInformation,
      userIdentity,
      companyId,
      serialNo,
      jump,
      code,
      status,
      userStatus,
    } = this.props;

    //0:正常,1:已停用,2:变更审核中,3:变更已驳回,4:审核中,5:已驳回,6:暂存,7:变更暂存
    //const { state } = information;
    const { tableKey } = this.state;
    // 被改变过的信息Json对象化
    let changedInformation = companyChangeLog.json;
    console.log(userInformation)
    function renderField(fieldName, render) {
      if (fieldName in changedInformation) {
        return render ? (
          render(changedInformation[fieldName])
        ) : (
          <span>
            <label style={{ color: 'red', marginRight:10 }}><del>{information[fieldName]}</del></label>
            <label style={{ color: '#000' }}>{changedInformation[fieldName]}</label>
          </span>
        );
      }
      return information[fieldName];
    }

    const companys = ['集团', '独立公司', '法人公司'];
    return (
      <>
        {/* 公司信息 */}
        {/*驳回、暂存状态可编辑，审核状态不可编辑*/}
        { //只有公司创建审核：BL003 and 公司变更审核:BL004 才显示
          (code === 'BL003' || code === 'BL004') && (
            <CompanysInfo
              headStyle={headStyle}
              renderField={renderField}
              changedInformation={changedInformation}
              changedImg={changedImg}
            />

          )
        }

        {/* 法人代表信息 */}
        { //只有公司创建审核：BL003 and 公司变更审核:BL004 and 实名认证: BL005才显示
          (code === 'BL003' || code === 'BL004') && (
            <CorporateInfo
              headStyle={headStyle}
              renderField={renderField}
              changedInformation={changedInformation}
              changedImg={changedImg}
              formatDate={formatDate}
              code={code}
            />

          )
        }

        {/* 管理员信息 */}
        {
          (code === 'BL003' || code === 'BL004') && (
            <AdministratorInfo
              headStyle={headStyle}
              renderField={renderField}
              changedInformation={changedInformation}
              changedImg={changedImg}
              userStatus={userStatus}
            />
          )
        }

        {/* 实名认证信息 */}
        { //实名认证: BL005才显示
          (code === 'BL005') && (
            <Authentication
              headStyle={headStyle}
              companyChangeLog={companyChangeLog}
              userInformation={userInformation}
              changedImg={changedImg}
              formatDate={formatDate}
            />
          )
        }

        {//变更审核、变更驳回、创建审核、创建驳回要审核结果
            (status === 1 && (typeof reviewResult !== "undefined")) && (
                <Card title="审核结果" style={{ marginBottom: '20px' }} headStyle={headStyle}>
                <div style={{ display: 'flex' }}>
                    <Icon
                    type={`${['clock', 'check', 'close'][reviewResult.verificationState]}-circle`}
                    theme="filled"
                    style={{
                        color: ['#1890ff', 'green', 'red'][reviewResult.verificationState],
                        margin: '4px 10px 0 0',
                    }}
                    />
                    <div>
                    <div style={{ marginBottom: '10px' }}>审核说明：{reviewResult.processRemark}</div>
                    <div>
                        <span>审核时间：{reviewResult.updateTime && getDate(reviewResult.updateTime)}</span>
                        <span style={{ margin: '0 10px' }}>审核人：{reviewResult.updateBy}</span>
                        <span>
                        审核类型：
                        {['待验证', '验证通过', '验证不通过'][reviewResult.verificationState]}
                        </span>
                    </div>
                    </div>
                </div>
                </Card>
            )
        }

        {
            //0:正常,1:已停用,2:变更审核中,3:变更已驳回,4:审核中,5:已驳回,6:暂存,7:变更暂存
            (status === 0) && (
              <AuditResults
                key={tableKey}
                headStyle={headStyle}
                serialNo={serialNo}
                dispatch={dispatch}
                code={code}
              />
              )
        }

      </>
    );
  }
}

export default CompanyInformation;
